﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BOSS.Framework.Search.UrlBuilder
{
    /// <summary>
    /// 抽象 URL 构造器
    /// </summary>
    public abstract class AbstractUrlBuilder : IUrlBuilder
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="urlFormat"></param>
        /// <param name="userData"></param>
        public AbstractUrlBuilder(string urlFormat, object userData)
        {
            this.UrlFormat = urlFormat;
            this.UserData = userData;
        }

        /// <summary>
        /// URL 格式
        /// </summary>
        protected string UrlFormat { get; private set; }

        /// <summary>
        /// 用户数据
        /// </summary>
        public object UserData { get; set; }

        #region IUrlBuilder Members

        /// <summary>
        /// 获取 构造器名称
        /// </summary>
        public abstract string Name { get; }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="contentType"></param>
        public abstract void Initialize(string contentType);

        /// <summary>
        /// 开始设置过滤参数
        /// </summary>
        public abstract void BeginFilter();

        /// <summary>
        /// 设置 过滤参数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        public abstract void SetFilter(string fieldName, int value);

        /// <summary>
        /// 设置 过滤参数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        public abstract void SetFilter(string fieldName, decimal value);

        /// <summary>
        /// 设置 过滤参数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="value"></param>
        public abstract void SetFilter(string fieldName, string value);

        /// <summary>
        /// 设置 过滤参数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        public abstract void SetFilter(string fieldName, int minValue, bool includeMinValue, int maxValue, bool includeMaxValue);

        /// <summary>
        /// 设置 过滤参数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        public abstract void SetFilter(string fieldName, decimal minValue, bool includeMinValue, decimal maxValue, bool includeMaxValue);

        /// <summary>
        /// 设置 过滤参数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="minValue"></param>
        /// <param name="includeMinValue"></param>
        /// <param name="maxValue"></param>
        /// <param name="includeMaxValue"></param>
        public abstract void SetFilter(string fieldName, DateTime minValue, bool includeMinValue, DateTime maxValue, bool includeMaxValue);

        /// <summary>
        /// 完成过滤参数的设置
        /// </summary>
        public abstract void EndFilter();

        /// <summary>
        /// 开始设置排序参数
        /// </summary>
        public abstract void BeginSort();

        /// <summary>
        /// 设置 排序参数
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="descend"></param>
        public abstract void SetSort(string fieldName, bool descend);

        /// <summary>
        /// 完成排序参数的设置
        /// </summary>
        public abstract void EndSort();

        /// <summary>
        /// 设置 分页大小
        /// </summary>
        /// <param name="pageSize"></param>
        public abstract void SetPageSize(int pageSize);

        /// <summary>
        /// 获取 URL
        /// </summary>
        /// <param name="pageIndex">当前页序号</param>
        /// <returns></returns>
        public abstract string GetUrl(int pageIndex);

        #endregion
    }
}
